home *** CD-ROM | disk | FTP | other *** search
-
-
-
- FOPEN(3) MINTLIB LIBRARY FUNCTIONS FOPEN(3)
-
-
- N✓NA✓AM✓ME✓E
- fopen, freopen, fdopen - open a stream
-
- S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S
- #include <stdio.h>
-
- FILE *fopen(const char *filename, const char *type);
-
- FILE *freopen(const char *filename, const char *type,
- FILE *stream);
-
- FILE *fdopen(int fd, const char *type);
-
- D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N
- fopen opens the file named by filename and associates a
- stream with it. If the open succeeds, fopen returns a
- pointer to be used to identify the stream in subsequent
- operations.
-
- filename points to a character string that contains the
- name of the file to be opened.
-
- type is a character string starting with one the following
- values:
- r - open for reading
- w - truncate or create for writing
- a - append: open for writing at end of file, or create
- for writing
- r+ - open for update (reading and writing)
- w+ - truncate or create for update
- a+ - append; open or create for update at EOF
-
- After one of the above, type may be followed by:
- t - open file in text mode (translate rn to n when
- reading, and n to rn when writing)
- b - open file in binary mode (no r, n translation)
-
- If neither 't' nor 'b' is set, the file will be opened in
- the default mode set by the user. If the environment vari-
- able UNIXMODE contains the letter 'b', the default mode
- will be binary; otherwise, the default mode is text mode.
-
- freopen opens the file named by filename and associates
- the stream pointed to by stream with it. The type argument
- is used just as in fopen. The original stream is closed,
- regardless of whether the open ultimately succeeds. If the
- open succeeds, freopen returns the original value of
- stream.
-
- freopen is typically used to attach the preopened streams
- associated with stdin, stdout, and stderr to other files.
-
- fdopen associates a stream with the file descriptor fd.
- File descriptors are obtained from calls like open, dup,
-
-
-
- MiNT docs 0.1 3 March 1993 1
-
-
-
-
-
- FOPEN(3) MINTLIB LIBRARY FUNCTIONS FOPEN(3)
-
-
- creat, or pipe, which open files but do not return
- streams. Streams are necessary input for many of the
- library routines. The type of the stream must agree with
- the access permissions of the open file.
-
- When a file is opened for update, both input and output
- may be done on the resulting stream. However, output may
- not be directly followed by input without an intervening
- fseek or rewind, and input may not be directly followed by
- output without an intervening fseek, rewind, or an input
- operation which encounters EOF.
-
- R✓RE✓ET✓TU✓UR✓RN✓N V✓VA✓AL✓LU✓UE✓ES✓S
- On success, fopen, freopen, and fdopen return a pointer
- to FILE which identifies the opened stream. On failure,
- they return NULL.
-
- S✓SE✓EE✓E A✓AL✓LS✓SO✓O
- o✓op✓pe✓en✓n(✓(3✓3)✓),✓, p✓pi✓ip✓pe✓e(✓(3✓3)✓),✓, f✓fc✓cl✓lo✓os✓se✓e(✓(3✓3)✓),✓, f✓fs✓se✓ee✓ek✓k(✓(3✓3)✓)
-
- B✓BU✓UG✓GS✓S
- The library allows only a limited number of streams to be
- open at the same time. Thus, a program may run out of
- streams even though the system is not yet out of memory.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MiNT docs 0.1 3 March 1993 2
-
-
-